/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022.
 * Description: irq bypass
 * Author: lilinjie8 <lilinjie8@huawei.com>
 * Create: 2022-01-24
 */

#ifndef HPVISOR_IRQBYPASS_H
#define HPVISOR_IRQBYPASS_H

#include <linux/types.h>
#include <linux/irq.h>
#include <linux/kvm_host.h>

#define HPVISOR_IRQ_BYPASS 1

int hpvisor_arch_find_pcpu(int vcpu);
void hpvisor_vcpu_irq_data_destroy(struct kvm_vcpu *vcpu);
void hpvisor_arch_irq_bypass_release(const struct kvm *kvm);
int hpvisor_arch_ioctl_intr_stage2_map(struct kvm *kvm, unsigned long arg);
int hpvisor_arch_ioctl_irq_bypass_init(struct kvm *kvm, unsigned long arg);

void hpvisor_vcpu_set_wfx_not_trap(struct kvm_vcpu *vcpu);

static inline bool hpvisor_vcpu_check_irq_bypass(const struct kvm_vcpu *vcpu)
{
	return vcpu && vcpu->gic_mode == HPVISOR_IRQ_BYPASS;
}

static inline bool hpvisor_vcpu_check_irq_received(const struct kvm_vcpu *vcpu)
{
	return vcpu && vcpu->irq_data.received;
}
#endif
